/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-02-19
 * Time: 14:45
 */
public class test1 {
    /**
     * LeetCode  LCR002    二进制求和
     */

    public String addBinary(String a, String b) {
        int cur1 = a.length()-1;
        int cur2 = b.length()-1;
        StringBuffer ret = new StringBuffer();
        // 用于判断进位
        int t = 0;
        while(cur1>=0 || cur2>=0 || t!=0){
            if(cur1>=0){
                t+=a.charAt(cur1--) - '0';
            }
            if(cur2>=0){
                t+=b.charAt(cur2--) - '0';
            }
            ret.append((char)(t%2+'0'));
            t /= 2;
        }
        return ret.reverse().toString();
    }
}
